package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.vo.TranslateVo;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.tmt.v20180321.TmtClient;
import com.tencentcloudapi.tmt.v20180321.models.TextTranslateRequest;
import com.tencentcloudapi.tmt.v20180321.models.TextTranslateResponse;
import org.springframework.stereotype.Service;


@Service
public class SysTranslateImpl {

    public String translate(TranslateVo translateVo){

        String result = "";

        try {
            Thread.sleep(200);
            Credential cred = new Credential("AKIDra7SaUAg06zhDVZRDm7FB0e7OSJxPehj","3vkYCgy42qUyJURA9zd9VXUHqDPRM4eN");
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("tmt.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            TmtClient client = new TmtClient(cred, "ap-beijing", clientProfile);
            TextTranslateRequest req = new TextTranslateRequest();
            req.setSourceText(translateVo.getText());
            req.setSource(translateVo.getFrom());
            req.setTarget(translateVo.getTo());
            req.setProjectId(0L);

            TextTranslateResponse resp = client.TextTranslate(req);

            result =resp.getTargetText();
            System.out.println("result:" + result);
        } catch (TencentCloudSDKException | InterruptedException e) {
            System.out.println(e);
        }

        return result;

    }

}
